package cn.stylefeng.guns.modular.rest;


import cn.stylefeng.guns.modular.school.entity.ClassTeacherLession;
import cn.stylefeng.guns.modular.school.entity.StudentInfo;
import cn.stylefeng.guns.modular.school.entity.TeacherInfo;
import cn.stylefeng.guns.modular.school.model.params.ClassMsgParam;
import cn.stylefeng.guns.modular.school.model.params.ClassTeacherLessionParam;
import cn.stylefeng.guns.modular.school.model.params.ExamScoreParam;
import cn.stylefeng.guns.modular.school.model.result.ClassMsgResult;
import cn.stylefeng.guns.modular.school.model.result.ExamScoreResult;
import cn.stylefeng.guns.modular.school.service.*;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 绑定控制器
 *
 * @author
 * @Date 2019-11-18 13:24:11
 */
@RestController
@RequestMapping("/gunsApi/msg")
public class ApiNeedMsgController extends BaseController {

    @Autowired
    private StudentInfoService studentInfoService;
    @Autowired
    private TeacherInfoService teacherInfoService;
    @Autowired
    private ClassTeacherLessionService classTeacherLessionService;
    @Autowired
    private ExamScoreService examScoreService;
    @Autowired
    private ClassMsgService classMsgService;

    @RequestMapping(value = "list")
    public Object list(String userCode) {
        Map map = new HashMap();
        List<Integer> classIds = new ArrayList<>();

        StudentInfo student = studentInfoService.findByCode(userCode);
        if (student == null) {
            ClassTeacherLessionParam classTeacherLessionParam = new ClassTeacherLessionParam();
            TeacherInfo teacherInfo = teacherInfoService.findByCode(userCode);
            classTeacherLessionParam.setTeacherId(teacherInfo.getId());
            // 教师教课的所有班
            List<ClassTeacherLession> classes = classTeacherLessionService.findByTeacherId(classTeacherLessionParam);
            classes.forEach(classTeacherLession -> {
                classIds.add(classTeacherLession.getClassId());
            });

            ClassMsgParam param = new ClassMsgParam();
            param.setClassIdList(classIds);
            List<ClassMsgResult> classMsgResults = classMsgService.findListByClassIds(param);

            map.put("msgs", classMsgResults);
        } else {
            ClassMsgParam param = new ClassMsgParam();
            classIds.add(student.getClassId());
            param.setClassIdList(classIds);
            List<ClassMsgResult> classMsgResults = classMsgService.findListByClassIds(param);

            map.put("msgs", classMsgResults);
        }


        SUCCESS_TIP.setData(map);
        return SUCCESS_TIP;
    }

}


